package main

import (
	"context"
	"fmt"
	"goproject/grpc/blog/blogpb"
	"log"

	"google.golang.org/grpc"
)

func main() {
	opts := grpc.WithInsecure()
	cc, err := grpc.Dial("127.0.0.1:8801", opts)
	if err != nil {
		log.Fatalf("could not connect: %v", err)
	}
	defer cc.Close() //
	c := blogpb.NewBlogServiceClient(cc)
	// create Blog
	fmt.Println("Creating the blog")
	blog := &blogpb.Blog{
		Id:       "1234567890",
		AuthorId: "Stephane",
		Title:    "My First Blog",
		Content:  "Content of the first blog",
	}
	createBlogRes, err := c.CreateBlog(context.Background(), &blogpb.CreateBlogRequest{Blog: blog})
	fmt.Println(createBlogRes.GetBlog().GetTitle())
}
